﻿/**
* QSmart Andon
*
* 2012-10-10
* 
* steven.li
*
* Copyright(c) 2012 All Rights Reserved. Taiyou Tech(GUANGZHOU) Co.,Ltd.  (广州太友科技) [ sales@gztaiyou.com]. 
*
*/
using System;
using System.Collections;
using FX.CC.Andon.Entity.SystemManage;
using FX.CC.Andon.Service.SystemManage;
using FX.CC.Andon.Utility.Json;

namespace FX.CC.Andon.Business.SystemManage
{
    public class RoleBusiness
    {
        private readonly RoleService _dal = new RoleService();

        /// <summary>
        /// 获取部门绑定下拉列表
        /// </summary>
        /// <returns></returns>
        public string GetRoleList()
        {
            return JsonHelper.Encode(_dal.GetRoleList());
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public bool Remove(string roleId)
        {
            return _dal.Remove(roleId);
        }
        /// <summary>
        /// 获取角色分页
        /// </summary>
        /// <param name="qcmodel"></param>
        /// <returns></returns>
        public string GetRoleList(RoleQcEntity qcmodel)
        {
            var total = _dal.GetRoleCount(qcmodel);
            var list = _dal.GetRoleList(qcmodel);
            return JsonHelper.Encode(total, list);
        }

        public string GetRoleInfo(string roleId)
        {
            return JsonHelper.Encode(_dal.GetRoleInfo(roleId));
        }

        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool AddRole(string data)
        {
            var model = new RoleEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.RoleID = Guid.NewGuid();
                model.RoleName = row["RoleName"].ToString();
                model.OpRight = Convert.ToInt32(row["OpRight"].ToString());
                model.SignRight = Convert.ToInt32(row["SignRight"].ToString());
                model.FixRight = Convert.ToInt32(row["FixRight"].ToString());
                model.Remark = row["Remark"].ToString();
            }
            return _dal.AddRole(model);
        }

        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="data"></param>
        public bool ModifyRole(string data)
        {
            var model = new RoleEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.RoleID = new Guid(row["RoleID"].ToString());
                model.RoleName = row["RoleName"].ToString();
                model.OpRight = Convert.ToInt32(row["OpRight"].ToString());
                model.SignRight = Convert.ToInt32(row["SignRight"].ToString());
                model.FixRight = Convert.ToInt32(row["FixRight"].ToString());
                model.Remark = row["Remark"].ToString();
            }
            return _dal.ModifyRole(model);
        }

        public int GetRoleCount(string roleId)
        {
            return _dal.GetRoleCount(roleId);
        }
    }
}
